package de.jmda.sample.xml;

import java.io.File;
import java.io.IOException;
import java.util.Map;
import java.util.Set;

import org.apache.commons.io.FileUtils;

public abstract class JAXBIndexFileWriter
{
	public static void run(File rootDirectory) throws IOException
	{
		// parameter check
		if (rootDirectory == null)
		{
			throw new IllegalArgumentException(
					"parameter rootDirectory must not be null");
		}
		if (rootDirectory.exists() == false)
		{
			throw new IOException(
					"rootDirectory [" + rootDirectory.getAbsolutePath() +
					"] does not exist");
		}
		// parameter check end
		
		Map<File, Set<String>> indexData =
				JAXBIndexDataBuilder.build(rootDirectory);
		
		for (File packageDirectory : indexData.keySet())
		{
			FileUtils.writeLines(
					new File(packageDirectory, "jaxb.index"),
					indexData.get(packageDirectory));
		}
	}
}